from sqlalchemy import create_engine, Column, Integer, String, Float, ForeignKey, DateTime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, relationship

DB_URL = "mysql+pymysql://root:5define7eS@localhost:3306/ssequestions?charset=utf8mb4"

# 2. 创建数据库引擎（负责与数据库建立连接）
engine = create_engine(
    DB_URL,
    echo=True,  # echo=True 会打印 SQL 执行日志，开发时可开启，生产时关闭
    pool_pre_ping=True  # 连接前检查有效性，避免无效连接
)

Base = declarative_base()  # 3. 创建基类
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)  # 4. 创建会话工厂